from enum import Enum


class AppHttpCodeEnum(Enum):
    # 成功段 0
    SUCCESS = (200, "操作成功")

    # 登录段 1~50
    NEED_LOGIN = (1, "需要登录后操作")
    LOGIN_PASSWORD_ERROR = (2, "密码错误")

    # TOKEN 50~100
    TOKEN_INVALID = (50, "无效的TOKEN")
    TOKEN_EXPIRE = (51, "TOKEN已过期")
    TOKEN_REQUIRE = (52, "TOKEN是必须的")

    # SIGN 验签 100~120
    SIGN_INVALID = (100, "无效的SIGN")
    SIGN_TIMEOUT = (101, "SIGN已过期")

    # 参数错误 500~1000
    PARAM_REQUIRE = (500, "缺少参数")
    PARAM_INVALID = (501, "无效参数")
    PARAM_IMAGE_FORMAT_ERROR = (502, "图片格式有误")
    SERVER_ERROR = (503, "服务器内部错误")

    # 数据错误 1000~2000
    DATA_EXIST = (1000, "数据已经存在")
    AP_USER_DATA_NOT_EXIST = (1001, "ApUser数据不存在")
    DATA_NOT_EXIST = (1002, "数据不存在")

    # 权限错误 3000~3500
    NO_OPERATOR_AUTH = (3000, "无权限操作")
    NEED_ADMIN = (3001, "需要管理员权限")

    # 测试脚本内部状态 4000-5000
    CLIENT_INIT_FAIL = (4000, '客户端启动失败')
    SWITCH_ENV_FILE = (4001, '切换环境失败')
    REBOOT_CLIENT_SUCCESS = (4002, '重启客户端成功')
    BUSINESS_LOGIN_FAIL = (4003, '商家登录失败')
    SWITCH_LANGUAGE_FILE = (4004, '切换语言失败')
    CLERK_LOGIN_FAIL = (4005, '店员登录失败')

    INSERT_SHOPPING_CHART_FILE = (4101, '添加购物车失败')
    GOODS_PRE_PAGE_FILE = (4102, '商品页返回上一页失败')
    GOODS_NEXT_PAGE_FILE = (4103, '商品页到下一页失败')
    DIRECT_PAY_FILE = (4103, '购物车页直接支付失败')
    BUSINESS_BUTTON_ACTION_FILE = (4104, '商家折扣按钮点击失败')
    SWITCH_BUSINESS_DISCOUNT_TYPE_FILE = (4105, '切换商家折扣类型失败')
    INSERT_BUSINESS_DISCOUNT_NUM_FILE = (4106, '填入商家折扣失败')
    USER_COUPON_BUTTON_ACTION_FILE = (4107, '用户优惠券按钮点击失败')
    SEARCH_VIP_BUTTON_ACTION_FILE = (4108, '搜索VIP信息按钮点击失败')
    SEARCH_VIP_FILE = (4109, '搜索VIP操作失败')
    GET_COUPON_FILE = (4110, '添加优惠券失败')
    PAY_OPERATION_FILE = (4111, '支付操作失败（eg: 选择现金支付并输入金额）')
    PAY_BUTTON_ACTION_FILE = (4112, '支付确认失败')
    BEHIND_PAY_CLOSE_POPUP_FILE = (4113, '支付后关闭小窗失败')
    SWITCH_SIDEBAR_FILE = (4114, '切换侧边栏失败')
    REMOVE_CHART_FILE = (4115, '清除购物车失败')
    REBACK_FILE = (4116, '支付页返回点单页失败')
    BEHIND_EXCEPTION_LOGIN_SUCCESS = (4117, '异常发生后登录成功')
    USE_BALANCE_FILE = (4118, '使用余额失败')
    SMALL_CHANGE_FILE = (4119, '抹零失败')
    VIEW_TURNOVER_DETAIL_FILE = (4120, '查看交接班详情失败')
    TURNOVER_DETAIL_BACK_FILE = (4121, '交接班详情返回失败')

    CASE_ERROR_RECOVER_FILE = (4200, '用例失败时恢复原状失败')

    def __init__(self, code: int, error_message: str):
        self._code = code
        self._error_message = error_message

    @property
    def code(self) -> int:
        """获取状态码"""
        return self._code

    @property
    def error_message(self) -> str:
        """获取错误消息"""
        return self._error_message

    def to_dict(self):
        """转换为字典格式"""
        return {"code": self.code, "error_message": self.error_message}


# 测试代码
if __name__ == "__main__":
    print(AppHttpCodeEnum.SUCCESS.code)  # 200
    print(AppHttpCodeEnum.SUCCESS.error_message)  # "操作成功"
    print(AppHttpCodeEnum.NEED_LOGIN.to_dict())  # {'code': 1, 'error_message': '需要登录后操作'}
